package ro.dandanciu.webgallery.domainmodel;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author Dan
 *
 */
@Entity
@Table(name="TP_IMAGE")
@NamedQueries ( {
	@NamedQuery(
			name = "Image.GetByGalleryId", 
			query = "select i from Image i where i.parent.id = :galleryId"),
	@NamedQuery(
			name = "Image.DeleteByGalleryIdAndFileName", 
			query = "delete from Image i where i.parent.id = :galleryId and name = :name ")
}
)
public class Image {
	
	/**
	 * The identifier of the image.
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name="K_IMAGE", length=30)
	private long id;
	
	/**
	 * The name of the image.
	 */
	@Column(name="C_NAME", length=60) 
	private String name;
	
	@Column(name="C_TYPE", length=40) 
	private String contentType;
	
	/**
	 * A description of the image.
	 */
	@Column(name="N_SIZE", length=200) 
	private long size;
	
	/**
	 * Parent gallery, if null, then is root gallery.
	 */
	@ManyToOne
	@JoinColumn(name="F_PARENT")
	private Gallery parent;

	/**
	 * The timestamp of the last time this item was updated.
	 * Mapped to D_UPDATED.
	 */
	@Column(name="D_UPDATED")
	@Temporal(value=TemporalType.TIMESTAMP)
	private Date updated;
	
	/**
	 * The user id/software which has performed the last update.
	 * Mapped to C_UPDATER.
	 */
	@Column(name="C_UPDATER", length=30) 
	private String updater;
	
	
	public Date getUpdated() {
		return updated;
	}

	public void setUpdated(Date updated) {
		this.updated = updated;
	}

	public String getUpdater() {
		return updater;
	}

	public void setUpdater(String updater) {
		this.updater = updater;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	}

	public Gallery getParent() {
		return parent;
	}

	public void setParent(Gallery parent) {
		this.parent = parent;
	}

	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	public String toString() {
		return "Image(@id=" + id + ", name=" + name + ")"; 
	}
}
